<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Index extends MY_Controller {

	function __construct() {
		parent::__construct();
		$this -> sidebar = "Index";
		
	}

	function Index() {
		redirect('/admin', 'refresh');
	}
	function Wx(){
		$this->load->view('home/index');
	}
	function saveAttend(){
		$this->load->library('ProjectService/attend_service');
		/*$attend=$_POST['attend'];
		foreach ((new CourseName)->getAll()as $k => $v) {
			if($attend[3]==$v[XPHEnum::Caption]){
				$age_groups=$v[XPHEnum::Value];
			}
		}*/
		$attend=$_POST['attend'];
		foreach ((new CourseName)->getAll()as $k => $v) {
			if($attend[3]==$v[XPHEnum::Caption]){
				$courseName=$v[XPHEnum::Value];
			}
		}		
		foreach ((new AgeGroups)->getAll()as $k => $v) {
			if($attend[7]==$v[XPHEnum::Caption]){
				$age_groups=$v[XPHEnum::Value];
			}
		}
		foreach ((new TeachersAttribute)->getAll()as $k => $v) {
			if($attend[8]==$v[XPHEnum::Caption]){
				$teachers_attribute=$v[XPHEnum::Value];
			}
		}
		
		//教学水平
		$teachingLevel=$_POST['teachingLevel'];
		$teachingLevel_rank=array('0','0','0','0','0');
		$teachingLevel_count=0;		
		foreach ($teachingLevel as $k => $v) {
			$teachingLevel_count=$teachingLevel_count+$teachingLevel[$k];			
		}
		if($teachingLevel_count>=90){
			$teachingLevel_rank[0]='1';
		}else if($teachingLevel_count>=80 and $teachingLevel_count<90){
			$teachingLevel_rank[1]='1';
		}else if($teachingLevel_count>=70 and $teachingLevel_count<80){
			$teachingLevel_rank[2]='1';
		}else if($teachingLevel_count>=60 and $teachingLevel_count<70){
			$teachingLevel_rank[3]='1';
		}else if($teachingLevel_count<60){
			$teachingLevel_rank[4]='1';			
		}

		//教学效果
		$teachingEffect=$_POST['teachingEffect'];
		$teachingEffect_rank=array('0','0','0','0','0');
		$teachingEffect_count=0;		
		foreach ($teachingEffect as $k => $v) {
			$teachingEffect_count=$teachingEffect_count+$teachingEffect[$k];				
		}
		if($teachingEffect_count>=90){
			$teachingEffect_rank[0]='1';
		}else if($teachingEffect_count>=80 and $teachingEffect_count<90){
			$teachingEffect_rank[1]='1';
		}else if($teachingEffect_count>=70 and $teachingEffect_count<80){
			$teachingEffect_rank[2]='1';
		}else if($teachingEffect_count>=60 and $teachingEffect_count<70){
			$teachingEffect_rank[3]='1';
		}else if($teachingEffect_count<60){
			$teachingEffect_rank[4]='1';			
		}

		$teachingReadiness=$_POST['teachingReadiness'];
		$studentsNorm=$_POST['studentsNorm'];
/*        $classroom_facilities=$_POST['classroom_facilities'];
        foreach ($classroom_facilities as $k => $v) {
        	foreach ((new ClassroomFacilities)->getAll() as $k1 => $v1) {
        		if ($v==$v1[XPHEnum::Value]){
        			$v=$v1[XPHEnum::Caption];
        		}
        	}
        }
        $classroom_environmental=$_POST['classroom_environmental'];
        foreach ($classroom_environmental as $k => $v) {
        	foreach ((new ClassroomEnvironmental)->getAll() as $k1 => $v1) {
        		if ($v==$v1[XPHEnum::Value]){
        			$v=$v1[XPHEnum::Caption];
        		}
        	}
        }*/
        $classroom_facilities=$_POST['classroom_facilities'];
        $classroom_environmental=$_POST['classroom_environmental'];
        foreach ((new ClassroomFacilities)->getAll()as $k => $v) {
        	if($classroom_facilities==$v[XPHEnum::Value]){
        		$classroom_facilities_item=$v[XPHEnum::Value];
        	}
        }
        foreach ((new ClassroomEnvironmental)->getAll()as $k => $v) {
        	if($classroom_environmental==$v[XPHEnum::Value]){
        		$classroom_environmental_item=$v[XPHEnum::Value];
        	}
        }
        $attend_record=$_POST['attend_record'];
        $recordcount=$_POST['recordcount']-1;
        $attend_record_value=array();
        $k =0;
        for ($i=0;$i<=$recordcount;$i++){
			//$item = array('time'=>$attend_record[$i-1].",activity"=>$attend_record[$i].",commentary"=>$attend_record[$i+1].")";			
        	$item['time'] =strtotime($attend_record[$k]);
        	$item['activity'] =$attend_record[$k+1];
        	$item['commentary'] =$attend_record[$k+2];
        	array_push($attend_record_value, $item);
        	$k+=3;
        }
        $attend_img=$this->NOTXSS_POST['attend_img'];
        
        $attend_img_value=array();
        for ($i=0;$i<=count($attend_img)-1;$i++){
        	$item['img'] = $attend_img[$i];
        	if (checkStringIsBase64($item['img'])) {
        		$checkRet = uploadImg($item['img'], 'attend_img');
        		if (!$checkRet['status']) {
        			exit(toRetJson($checkRet));
        		}
        		$data['img']=$checkRet["v"];
        		  		
        	} else {
        		exit(retJson('上传的图片格式不正确！', false));
        	}
        	array_push($attend_img_value, $data); 
        }


        $param=array(
			'attend'=>array(
				'class_id'=>1,
				'listen_id'=>getSess()['id'],
				'type'=>AttendType::School[XPHEnum::Value],
				'serial_no'=>111112232,
				'academic_year'=>$attend[0],//学年
				'semester'=>$attend[1],//学期
				'class_name'=>$attend[2],
				'teacher_name'=>$attend[3],
				'title'=>$attend[4],
				'dept_name'=>$attend[5],
				'age_groups'=>$age_groups,
				'teachers_attribute'=>$teachers_attribute,
				'listen_name'=>'李四',
				'listen_time'=>date('Y-m-d'),
				'listen_address'=>$attend[9],
				'course_units'=>$attend[10],
				'listen_class'=>$attend[11],
				'classroom_facilities'=>$classroom_facilities_item,
				'classroom_environmental'=>$classroom_environmental_item,
				'advice'=>'意见',
				'teaching_level_score'=>$teachingLevel_count,
				'teaching_effect_score'=>$teachingEffect_count
				),
			'attend_teaching_content'=>array(
				0=>array('content'=>TeachingContent::First[XPHEnum::Caption],'score'=>TeachingContent::First[XPHEnum::Remark],'get_score'=>$teachingLevel[0]),
				1=>array('content'=>TeachingContent::Second[XPHEnum::Caption],'score'=>TeachingContent::Second[XPHEnum::Remark],'get_score'=>$teachingLevel[1]),
				2=>array('content'=>TeachingContent::Third[XPHEnum::Caption],'score'=>TeachingContent::Third[XPHEnum::Remark],'get_score'=>$teachingLevel[2])
				),
			'attend_teaching_implementation'=>array(
				0=>array('content'=>TeachingImplementation::First[XPHEnum::Caption],'score'=>TeachingImplementation::First[XPHEnum::Remark],'get_score'=>$teachingLevel[3]),
				1=>array('content'=>TeachingImplementation::Second[XPHEnum::Caption],'score'=>TeachingImplementation::Second[XPHEnum::Remark],'get_score'=>$teachingLevel[4]),
				2=>array('content'=>TeachingImplementation::Third[XPHEnum::Caption],'score'=>TeachingImplementation::Third[XPHEnum::Remark],'get_score'=>$teachingLevel[5]),
				3=>array('content'=>TeachingImplementation::Fourth[XPHEnum::Caption],'score'=>TeachingImplementation::Fourth[XPHEnum::Remark],'get_score'=>$teachingLevel[6]),
				4=>array('content'=>TeachingImplementation::Fifth[XPHEnum::Caption],'score'=>TeachingImplementation::Fifth[XPHEnum::Remark],'get_score'=>$teachingLevel[7]),
				5=>array('content'=>TeachingImplementation::Sixth[XPHEnum::Caption],'score'=>TeachingImplementation::Sixth[XPHEnum::Remark],'get_score'=>$teachingLevel[8])	
				),
			'attend_teaching_level'=>array(
				0=>array('item'=>TeachingLevel::First[XPHEnum::Caption],'remark'=>TeachingLevel::First[XPHEnum::Remark],'is_check'=>$teachingLevel_rank[0]),
				1=>array('item'=>TeachingLevel::Second[XPHEnum::Caption],'remark'=>TeachingLevel::Second[XPHEnum::Remark],'is_check'=>$teachingLevel_rank[1]),
				2=>array('item'=>TeachingLevel::Third[XPHEnum::Caption],'remark'=>TeachingLevel::Third[XPHEnum::Remark],'is_check'=>$teachingLevel_rank[2]),
				3=>array('item'=>TeachingLevel::Fourth[XPHEnum::Caption],'remark'=>TeachingLevel::Fourth[XPHEnum::Remark],'is_check'=>$teachingLevel_rank[3]),
				4=>array('item'=>TeachingLevel::Fifth[XPHEnum::Caption],'remark'=>TeachingLevel::Fifth[XPHEnum::Remark],'is_check'=>$teachingLevel_rank[4])
				),
			'attend_student_status'=>array(
				0=>array('content'=>StudentStatus::First[XPHEnum::Caption],'score'=>StudentStatus::First[XPHEnum::Remark],'get_score'=>$teachingEffect[0]),
				1=>array('content'=>StudentStatus::Second[XPHEnum::Caption],'score'=>StudentStatus::Second[XPHEnum::Remark],'get_score'=>$teachingEffect[1]),
				2=>array('content'=>StudentStatus::Fourth[XPHEnum::Caption],'score'=>StudentStatus::Third[XPHEnum::Remark],'get_score'=>$teachingEffect[2]),
				3=>array('content'=>StudentStatus::Third[XPHEnum::Caption],'score'=>StudentStatus::Fourth[XPHEnum::Remark],'get_score'=>$teachingEffect[3]),
				4=>array('content'=>StudentStatus::Fifth[XPHEnum::Caption],'score'=>StudentStatus::Fifth[XPHEnum::Remark],'get_score'=>$teachingEffect[4])
				),
			'attend_teaching_effect'=>array(
				0=>array('item'=>'A','remark'=>TeachingEffect::First[XPHEnum::Remark],'is_check'=>$teachingLevel_rank[0]),
				1=>array('item'=>'B','remark'=>TeachingEffect::Second[XPHEnum::Remark],'is_check'=>$teachingLevel_rank[1]),
				2=>array('item'=>'C','remark'=>TeachingEffect::Third[XPHEnum::Remark],'is_check'=>$teachingLevel_rank[2]),
				3=>array('item'=>'D','remark'=>TeachingEffect::Fourth[XPHEnum::Remark],'is_check'=>$teachingLevel_rank[3]),
				4=>array('item'=>'E','remark'=>TeachingEffect::Fifth[XPHEnum::Remark],'is_check'=>$teachingLevel_rank[4])
				),
			'attend_teaching_readiness'=>array(
				0=>array('item'=>TeachingReadiness::First[XPHEnum::Caption],'option'=>TeachingReadiness::First[XPHEnum::Remark][0].','.TeachingReadiness::First[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[0]),
				1=>array('item'=>TeachingReadiness::Second[XPHEnum::Caption],'option'=>TeachingReadiness::Second[XPHEnum::Remark][0].','.TeachingReadiness::Second[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[1]),
				2=>array('item'=>TeachingReadiness::Third[XPHEnum::Caption],'option'=>TeachingReadiness::Third[XPHEnum::Remark][0].','.TeachingReadiness::Third[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[2]),
				3=>array('item'=>TeachingReadiness::Fourth[XPHEnum::Caption],'option'=>TeachingReadiness::Fourth[XPHEnum::Remark][0].','.TeachingReadiness::Fourth[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[3]),
				4=>array('item'=>TeachingReadiness::Fifth[XPHEnum::Caption],'option'=>TeachingReadiness::Fifth[XPHEnum::Remark][0].','.TeachingReadiness::Fifth[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[4]),
				5=>array('item'=>TeachingReadiness::Sixth[XPHEnum::Caption],'option'=>TeachingReadiness::Sixth[XPHEnum::Remark][0].','.TeachingReadiness::Sixth[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[5]),
				6=>array('item'=>TeachingReadiness::Seventh[XPHEnum::Caption],'option'=>TeachingReadiness::Seventh[XPHEnum::Remark][0].','.TeachingReadiness::Seventh[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[6]),
				7=>array('item'=>TeachingReadiness::Eighth[XPHEnum::Caption],'option'=>TeachingReadiness::Eighth[XPHEnum::Remark][0].','.TeachingReadiness::Eighth[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[7]),
				8=>array('item'=>TeachingReadiness::Ninth[XPHEnum::Caption],'option'=>TeachingReadiness::Ninth[XPHEnum::Remark][0].','.TeachingReadiness::Ninth[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[8]),
				9=>array('item'=>TeachingReadiness::Tenth[XPHEnum::Caption],'option'=>TeachingReadiness::Tenth[XPHEnum::Remark][0].','.TeachingReadiness::Tenth[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[9]),
				10=>array('item'=>TeachingReadiness::Eleventh[XPHEnum::Caption],'option'=>TeachingReadiness::Eleventh[XPHEnum::Remark][0].','.TeachingReadiness::Eleventh[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[10]),
				11=>array('item'=>TeachingReadiness::Twelfth[XPHEnum::Caption],'option'=>TeachingReadiness::Twelfth[XPHEnum::Remark][0].','.TeachingReadiness::Twelfth[XPHEnum::Remark][1],'check_value'=>$teachingReadiness[11])
				),
			'attend_students_norm'=>array(
				0=>array('item'=>StudentsNorm::First[XPHEnum::Caption],'check_value'=>$studentsNorm[0]),
				1=>array('item'=>StudentsNorm::Second[XPHEnum::Caption],'check_value'=>$studentsNorm[1]),
				2=>array('item'=>StudentsNorm::Third[XPHEnum::Caption],'check_value'=>$studentsNorm[2]),
				3=>array('item'=>StudentsNorm::Fourth[XPHEnum::Caption],'check_value'=>$studentsNorm[3]),
				4=>array('item'=>StudentsNorm::Fifth[XPHEnum::Caption],'check_value'=>$studentsNorm[4]),
				5=>array('item'=>StudentsNorm::Sixth[XPHEnum::Caption],'check_value'=>$studentsNorm[5]),
				6=>array('item'=>StudentsNorm::Seventh[XPHEnum::Caption],'check_value'=>$studentsNorm[6]),
				7=>array('item'=>StudentsNorm::Eighth[XPHEnum::Caption],'check_value'=>$studentsNorm[7]),
				8=>array('item'=>StudentsNorm::Ninth[XPHEnum::Caption],'check_value'=>$studentsNorm[8])				
				),
			'attend_record'=> $attend_record_value,
        	'attend_img'=>$attend_img_value
        );
		$result=$this->attend_service->saveAttend($param,getSess(SESS_USER)['id']);//1.id,2,
		exit(retJson('数据增加成功', true,$result));
	}

    function Broadcast(){
        $this->load->model("Announcement_model");
        $title=$this->Announcement_model->query("select *  from db_announcement ");
        exit(retJson('获取标题', true,$title));
    }

    function popup(){
        $this->load->model("Announcement_model");
        $message=$this->Announcement_model->query("select *  from db_announcement  GROUP BY title");
        exit(retJson('获取信息', true,$message));
    }

}
